<template>
  <div class="container">
    <el-dialog width="60%" title="预览文章" :visible="showPreviewDialog" :before-close="handleclose">
      <h2>{{ preData.title }}</h2>
      <div class="tag">
        <span>{{ formatTimeData( preData. createTime ) }}</span>
        <span>{{ preData.username }}</span>
        <i class="el-icon-view" />
        <span>{{ preData. visits }}</span>
      </div>
      <div class="article-body">
        <p v-html="preData. articleBody" />
      </div>
    </el-dialog>
  </div>

</template>

<script>
import moment from "moment";
export default {
  name: 'ArticlesPreview',
  props: {
    showPreviewDialog: {
      type: Boolean,
      default: false
    },
    preData: {
      type: Object,
      default: () => ({})
    }

  },
  data () {
    return {

    }
  },

  methods: {

    formatTimeData (val) {
      return moment(val).format("yyyy-MM-DD hh:mm:ss");
    },
    // 通知父组件关闭对话框
    handleclose () {
      this.$emit('update:showPreviewDialog', false)
    }
  }
}
</script>

<style scoped lang='less'>
.container {
  h2 {
    margin-top: -5px;
  }
  .tag {
    text-indent: 10px;
    span {
      margin-right: 6px;
    }
    i {
      margin-right: 6px;
    }
  }
  .article-body {
    margin-top: 10px;
    // height: 80px;
    line-height: 40px;
    border-top: 1px dashed #ccc;
    background-color: #f5f5f5;
    border-radius: 3px;
    text-indent: 10px;
  }
}
</style>
